package hrm.action.cam;

import hrm.action.Action;
import hrm.action.ActionForward;
import hrm.dto.cam.CamViewDTO;
import hrm.paging.PageUtil;
import hrm.serviceimple.CamServiceImple;
import hrm.serviceimple.PagingServiceImple;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CamListCheck implements Action {

	@Override
	public ActionForward execute(HttpServletRequest request,
			HttpServletResponse response) {
		// TODO Auto-generated method stub
		ActionForward actfoward = new ActionForward();
		CamServiceImple camService = CamServiceImple.getInstance();
		PagingServiceImple pagingService = PagingServiceImple.getInstance();
		
		String namekor = request.getParameter("namekor");
		String id = request.getParameter("id");
		String camstartdate = request.getParameter("camstartdate");
		String camenddate = request.getParameter("camenddate");
		String camstate = request.getParameter("camstate");
		
		CamViewDTO dto = new CamViewDTO();
		dto.setNamekor(namekor);
		dto.setId(id);
		dto.setCamstartdate(camstartdate);
		dto.setCamenddate(camenddate);
		dto.setCamstate(camstate);
		
		List<CamViewDTO> checklist = camService.getAllCam(dto);
		
		dto = camService.getCam(dto);
		
		try {
			PageUtil.pageContollerHelp(pagingService, request, 10, 10, "getCamCountPaging", "getAllCamPaging", false);
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		request.setAttribute("detailCam", dto);
		request.setAttribute("checklist", checklist);
		actfoward.setUrl("detailCam");
		return actfoward;
	}

}
